package com.century.sjt.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.entity.MyOrderInfo;

import java.util.List;

/**
 * @author:周玲波
 * @Description: 商家、分店订单详情适配器
 * @date : 2016/9/5 16:15
 */
public class MerchantOrderDetailsAdapter extends BaseAdapter{
    Context mContext;
    List<MyOrderInfo> mList;
    LayoutInflater inflater;
    private Handler mHandler;
    public MerchantOrderDetailsAdapter(Context mContext, List<MyOrderInfo> mList, Handler mHandler) {
        this.mContext = mContext;
        this.mList = mList;
        this.mHandler = mHandler;
        inflater = LayoutInflater.from(mContext);
    }



    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.sjt_merchant_details_lv_item, null);
            holder.iv_goods_icon = (ImageView) convertView.findViewById(R.id.goods_icon);
            holder.tv_unit_price = (TextView) convertView.findViewById(R.id.tv_unit_price);
            holder.tv_total = (TextView) convertView.findViewById(R.id.tv_total);
            holder.tv_order_num = (TextView) convertView.findViewById(R.id.tv_order_num);
            holder.tv_goods_unit_price = (TextView) convertView.findViewById(R.id.tv_goods_unit_price);
            holder.tv_goods_name = (TextView) convertView.findViewById(R.id.tv_goods_name);
            holder.ll_rejected_total = (LinearLayout) convertView.findViewById(R.id.ll_rejected_total);
            holder.line = (View) convertView.findViewById(R.id.line);
            holder.ll_staus_two = (LinearLayout) convertView.findViewById(R.id.ll_staus_two);//退货退款
            holder.ll_staus_one = (LinearLayout) convertView.findViewById(R.id.ll_staus_one); //其它
            holder.tv_rejected_total = (TextView) convertView.findViewById(R.id.tv_rejected_total);
            holder.tv_buy_amount = (TextView) convertView.findViewById(R.id.tv_buy_amount);
            holder.tv_rejected_amount = (TextView) convertView.findViewById(R.id.tv_rejected_amount);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_unit_price.setText(mList.get(position).getUnitPrice());
        holder.tv_total.setText(mList.get(position).getTotal());
        holder.tv_goods_name .setText(mList.get(position).getGoodsName());
        holder.ll_rejected_total.setVisibility(View.GONE);
        holder.ll_staus_two.setVisibility(View.GONE);
        holder.ll_staus_one.setVisibility(View.GONE);
        holder.line.setVisibility(View.GONE);
        String Status = mList.get(position).getStatus();
        Log.e("Status",Status+"//"+mList.get(position).getGoodsName());
        switch (Status){
            case "5"://退货
                holder.ll_rejected_total.setVisibility(View.VISIBLE);
                holder.line.setVisibility(View.VISIBLE);
                holder.ll_staus_two.setVisibility(View.VISIBLE);
                holder.tv_rejected_total.setText(mList.get(position).getReturnAmount());
                holder.tv_buy_amount.setText(mList.get(position).getGoodsQuantity());
                holder.tv_rejected_amount.setText(mList.get(position).getReturnQuantity());
                break;
            case "6"://以退货
                holder.ll_rejected_total.setVisibility(View.VISIBLE);
                holder.ll_staus_two.setVisibility(View.VISIBLE);
                holder.line.setVisibility(View.VISIBLE);
                holder.tv_rejected_total.setText(mList.get(position).getReturnAmount());
                holder.tv_buy_amount.setText(mList.get(position).getGoodsQuantity());
                holder.tv_rejected_amount.setText(mList.get(position).getReturnQuantity());
                break;
            case "7"://退款
                holder.ll_rejected_total.setVisibility(View.VISIBLE);
                holder.ll_staus_two.setVisibility(View.VISIBLE);
                holder.line.setVisibility(View.VISIBLE);
                holder.tv_rejected_total.setText(mList.get(position).getReturnAmount());
                holder.tv_buy_amount.setText(mList.get(position).getGoodsQuantity());
                holder.tv_rejected_amount.setText(mList.get(position).getReturnQuantity());
                break;
            case "8"://以退款
                holder.ll_rejected_total.setVisibility(View.VISIBLE);
                holder.ll_staus_two.setVisibility(View.VISIBLE);
                holder.line.setVisibility(View.VISIBLE);
                holder.tv_rejected_total.setText(mList.get(position).getReturnAmount());
                holder.tv_buy_amount.setText(mList.get(position).getGoodsQuantity());
                holder.tv_rejected_amount.setText(mList.get(position).getReturnQuantity());
                break;
            default:
                holder.ll_staus_one.setVisibility(View.VISIBLE);
                holder.ll_staus_two.setVisibility(View.GONE);
                break;
        }



        holder.tv_order_num.setVisibility(View.VISIBLE);
        holder.tv_order_num.setText(mList.get(position).getGoodsQuantity());
        holder.tv_goods_unit_price.setVisibility(View.VISIBLE);
        holder.tv_goods_unit_price.setText(mList.get(position).getUnitPrice());
        holder.tv_unit_price.setVisibility(View.GONE);
        Glide.with(mContext).load(mList.get(position).getImage()).into(holder.iv_goods_icon);
        return convertView;
    }

    class ViewHolder {
        private ImageView iv_goods_icon;
        private TextView tv_unit_price;
        private TextView tv_total;
        private TextView tv_order_num;
        private TextView tv_goods_unit_price;
        private LinearLayout ll_rejected_total;
        private View line;
        private TextView tv_goods_name;
        private LinearLayout ll_staus_two;
        private LinearLayout ll_staus_one;
        private TextView tv_buy_amount;//购买数量
        private TextView tv_rejected_amount;//退货数量
        private TextView tv_rejected_total;//退款金额
    }
}
